home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_331 / csh / src / run.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  82 lines

  1.  
  2. /*
  3.  * RUN.C
  4.  *
  5.  * (c)1986 Matthew Dillon     9 October 1986
  6.  *
  7.  *    RUN   handles running of external commands.
  8.  *
  9.  * Version 2.07M by Steve Drew 10-Sep-87
  10.  *
  11.  * Version 4.01A by Carlo Borreo & Cesare Dieni 17-Feb-90
  12.  *
  13.  */
  14.  
  15. char *FindIt();
  16.  
  17. do_run(str)
  18. char *str;
  19. {
  20. int retcode;
  21. char buf[200]; /* enough space for 100 char cmd name + path stuff */
  22. char *path, *argline, *trueargline, *copy, *p = av[0];
  23.  
  24. while(*p++) *p &= 0x7F;      /* allow "com mand" */
  25.  
  26. argline=compile_av(av, 1, ac, ' ', 1);
  27. trueargline= (*argline ? argline : "\n");
  28.  
  29. if (strlen(av[0]) > 100) { ierror(NULL,509); return -1; }
  30.  
  31. sprintf(buf,"res_%s",BaseName(av[0]));
  32. if (Getenv(buf, buf+100, 90L) && loadres(av[0])) Setenv(buf,NULL);
  33. retcode=SyncRun(av[0],trueargline,0L,0L);
  34. if (retcode>=0) { free(argline); return retcode; }
  35. if (path = FindIt(av[0],"",buf)) {
  36.     retcode = SyncRun(path,trueargline,0L,0L);
  37.     free(argline);
  38.     return retcode;
  39.     }
  40. else free(argline);
  41. if ((path = FindIt(av[0],".sh",buf)) == NULL) {
  42.     fprintf(stderr,"Command Not Found %s\n",av[0]);
  43.     return -1;
  44.     }
  45. av[1] = buf;
  46. copy = malloc(strlen(str)+3);
  47. sprintf(copy,"x %s",str);
  48. retcode = do_source(copy);
  49. free(copy);
  50. return retcode;
  51. }
  52.  
  53. char *dofind(cmd, ext, buf)
  54. char *cmd, *ext, *buf;
  55. {
  56. char *ptr, *s;
  57.  
  58. sprintf(buf,"%s%s",cmd,ext);
  59. if (exists(buf)) return buf;
  60. if (BaseName(buf)==buf) {
  61.     s = get_var(LEVEL_SET, v_path);
  62.     while (*s) {
  63.         for (ptr=buf; *s && *s!=','; ) *ptr++ = *s++;
  64.         sprintf(ptr, "%s%s", cmd, ext);
  65.         if (exists(buf)) return buf;
  66.         if (*s) s++;
  67.         }
  68.     }
  69. return NULL;
  70. }
  71.  
  72. char *FindIt(cmd,ext,buf)
  73. char *cmd, *ext, *buf;
  74. {
  75. char *response;
  76.  
  77. Myprocess->pr_WindowPtr = (APTR)(-1);
  78. response=dofind(cmd,ext,buf);
  79. Myprocess->pr_WindowPtr = NULL;
  80. return response;
  81. }
  82.